import { Role, Auths } from './utils/typings.d';

/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
export default function access(initialState: { currentUser?: USER.CurrentUser } | undefined) {
  const { currentUser } = initialState || {};
  return {
    canAdmin: currentUser?.role === Role.ADMIN,
    canReadSystemUser: currentUser?.auth?.systemUser?.includes(Auths.READ),
    canReadSystemLog: currentUser?.auth?.systemLog?.includes(Auths.READ),
    canReadIotSim: currentUser?.auth?.iotSim?.includes(Auths.READ),
    canReadWebNav: currentUser?.auth?.webNav?.includes(Auths.READ),
    canReadSystemWarning: currentUser?.auth?.systemWarning?.includes(Auths.READ),
    canReadLogistics: currentUser?.auth?.logistics?.includes(Auths.READ),
  };
}
